import instance from "@/utils/axios.js";

// 获取用户频道
function getUserChannels() {
  return instance({
    url: "/v1_0/channels",
    methods: "get"
  });
}
export { getUserChannels };

// 获取文章列表
function getArticles({ channel_id, timestamp }) {
  return instance({
    url: "/v1_1/articles",
    method: "get",
    params: {
      channel_id,
      timestamp,
      with_top: 1
    }
  });
}

export { getArticles };

// 获取文章详情
function getArticleInfo(id) {
  return instance({
    url: `/v1_0/articles/${id}`,
    method: "get"
  });
}

export { getArticleInfo };

// 取消关注
function delFollowing(target) {
  return instance({
    url: `/v1_0/user/followings/${target}`,
    method: "delete"
  });
}

// 关注
function addFollowing({ target }) {
  return instance({
    url: "/v1_0/user/followings",
    method: "post",
    data: {
      target
    }
  });
}

export { addFollowing, delFollowing };

// 取消点赞
function delPraise(target) {
  return instance({
    url: `/v1_0/article/likings/${target}`,
    method: "delete"
  });
}

// 点赞
function addPraise({ target }) {
  return instance({
    url: "/v1_0/article/likings",
    method: "post",
    data: {
      target
    }
  });
}

export { delPraise, addPraise };

// 取消不喜欢
function delDislike(target) {
  return instance({
    url: `/v1_0/article/dislikes/${target}`,
    method: "delete"
  });
}

// 不喜欢
function addDislike({ target }) {
  return instance({
    url: "/v1_0/article/dislikes",
    method: "post",
    data: {
      target
    }
  });
}

export { delDislike, addDislike };

// 获取关联推荐列表
function getSuggestionList({ q }) {
  return instance({
    url: "/v1_0/suggestion",
    method: "get",
    params: { q }
  });
}

export { getSuggestionList };

// 获取用户的搜索历史
function getHistories() {
  return instance({
    url: "/v1_0/search/histories",
    method: "get"
  });
}

export { getHistories };
// 获取用户的搜索内容
function getSearchList(params) {
  return instance({
    url: "/v1_0/search",
    method: "get",
    params
  });
}

export { getSearchList };
